import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lcapp/api/interface/user_api.dart';
import 'package:lcapp/api/request/response_data.dart';
import 'package:lcapp/data/user_data_entity.dart';
import 'package:lcapp/model/toast/toast.dart';
import 'package:lcapp/widget/asr_cache_image.dart';

class SearchUserItem extends StatefulWidget {
  final UserDataEntity entity;
  final Function cilickFun;
  const SearchUserItem({Key? key, required this.entity, required this.cilickFun}) : super(key: key);

  @override
  _SearchUserItemState createState() => _SearchUserItemState();
}

class _SearchUserItemState extends State<SearchUserItem> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        if(widget.cilickFun!=null){
          widget.cilickFun();
        }
      },
      child: Container(
        margin: EdgeInsets.only(bottom: 20.w),
        child: Row(
          children: [
            Container(
              width: 100.w,
              height: 100.w,
              child: Stack(
                children: [
                  Center(
                    child: Container(
                      width: 100.w,
                      height: 100.w,
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(100.w)
                      ),
                    ),
                  ),
                  Center(
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(90.w),
                      child: ASRCacheImage(
                        width: 90.w,
                        height: 90.w,
                        fit: BoxFit.fitWidth,
                        image: widget.entity.img??'assets/icon/p_head.png',
                      ),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(width:30.w),
            Expanded(child: Container(
              height: 100.w,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Expanded(child:  Row(
                    children: [
                      Expanded(child: Text('${widget.entity.name}',style: TextStyle(
                          color: Color(0xff1A051D),
                          fontSize: 32.sp,
                          fontWeight: FontWeight.w600
                      ),)),
                      GestureDetector(
                        onTap: ()async{
                          showLoading();
                          ResponseData res = await UserAPI.followUser(widget.entity.id!);
                          hideLoading();
                          if(res.code==200){
                            setState(() {
                              if(widget.entity.attentionState==1){
                                widget.entity.attentionState=0;
                                showToast('已取消关注');
                              }else{
                                widget.entity.attentionState=1;
                                showToast('已关注');
                              }
                            });
                          }
                        },
                        child: Container(
                          width: 140.w,
                          height: 60.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(60.w),
                              gradient: LinearGradient(
                                colors: widget.entity.attentionState==1?[ Color(0xffE4E4E4),Color(0xffE4E4E4)]: [
                                  Color(0xffFF633B),
                                  Color(0xffFE4830),
                                ],
                                begin: Alignment.topCenter,
                                end: Alignment.bottomCenter,
                              )),
                          child: Text(widget.entity.attentionState==1?'取消关注':'关注',style: TextStyle(
                              color: Colors.white,
                              fontSize: 26.sp
                          ),),
                        ),
                      )
                    ],
                  ),),
                  Container(
                    height: 1,
                    color: Color(0xffE9E8E9),
                  ),
                ],
              ),
            ),),
          ],
        ),
      ),
    );
  }
}
